package com.fish.product.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fish.common.constant.QueryPage;
import com.fish.common.dao.BaseIbatisDao;
import com.fish.product.po.Product;
import com.fish.sight.po.Sight;

public class ProductDAO extends BaseIbatisDao {

	private static final Log loger = LogFactory.getLog(ProductDAO.class);
	public ProductDAO() {
		super();
	}

	/**
	 * 根据主键查询
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public Product queryProductByPrimaryKey(String productId) {
		loger.debug("queryProductByPrimaryKey:" + productId);
		return (Product) this.getSqlMapClientTemplate().queryForObject("PRODUCT.selectByPrimaryKey", productId);
	}

	/**
	 * 模糊查询
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	@SuppressWarnings("unchecked")
	public List<Product> queryProductByObject(Product product) {
		return (ArrayList<Product>) this.getSqlMapClientTemplate().queryForList("PRODUCT.queryByProduct", product);
	}

	/**
	 * 添加
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public void addProduct(Product product) {
		this.getSqlMapClientTemplate().insert("PRODUCT.insert", product);
	}
	
	/**
	 * 修改
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public void updateProduct(Product product) {
		this.getSqlMapClientTemplate().update("PRODUCT.updateByPrimaryKeySelective", product);
	}
	
	public Long queryPorductCountByObject(Product product){
		return  (Long) this.getSqlMapClientTemplate().queryForObject("PRODUCT.countProductWithPaging", product);
	}
	
	public  List<Product> queryProductByObject(Product product,QueryPage queryPage){
		product.setBeginItem(queryPage.getBeginItem());
		product.setEndItem(queryPage.getPageSize());
		return (List<Product>) this.getSqlMapClientTemplate().queryForList("PRODUCT.selectProductWithPaging", product);
	}

}